package com.app.entity;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;

import android.util.Log;

import com.app.web.HttpClientFactory;

public class PostEntity {
	//发表新帖或回复帖子的接口，使用前需检测是否登录
	public static boolean post(String content,String subject,String url){
		HttpPost httpRequest = new HttpPost(url);
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("content",content));
		params.add(new BasicNameValuePair("subject",subject));
		try{
			HttpEntity httpentity = new UrlEncodedFormEntity(params,"utf-8");
			httpRequest.setEntity(httpentity);
			HttpClient httpclient = HttpClientFactory.getHttpClient();
			HttpResponse httpResponse = httpclient.execute(httpRequest);
			Log.e("Post", httpResponse.toString());
			if(httpResponse.getStatusLine().getStatusCode()==HttpStatus.SC_OK){
				String strResult = EntityUtils.toString(httpResponse.getEntity());
				Log.e("Post", strResult);
				httpRequest.abort();
				if(strResult.contains("<div class=\"sp hl f\">����ɹ�</div>"))
					return true;
				else
					return false;
			}else
				return false;
		}catch(Exception e){
			Log.e("Post", e.getMessage().toString());
			return false;
		}
	}
}
